home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #6
/
Amiga Plus CD - 2004 - No. 06.iso
/
AmiSoft
/
Text
/
hyper
/
makeguide2.lha
/
MakeGuide2
/
MakeGuide2.c
< prev
next >
Wrap
C/C++ Source or Header
|
2003-12-15
|
27KB
|
810 lines
#define INTUI_V36_NAMES_ONLY
#include <exec/types.h>
#include <exec/libraries.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/asl.h>
#include <libraries/dos.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/asl_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/icon_protos.h>
#include <clib/dos_protos.h>
#include <stdio.h>
#include <dos.h>
#include <error.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MYGAD_PAT 0
#define MYGAD_SOURCE 1
#define MYGAD_SOURCEBUT 2
#define MYGAD_DEST 3
#define MYGAD_DESTBUT 4
#define MYGAD_TEMP 5
#define MYGAD_TEMPBUT 6
#define MYGAD_HEAD 7
#define MYGAD_HEADBUT 8
#define MYGAD_GOBUT 9
#define MYGAD_MSG 10
#define MYGAD_SORT 11
#define MYGAD_LEN 12
#define MYGAD_COLS 13
#define MYGAD_SUBIDX 14
#define MYGAD_ASCCHECK 15
#define MAXFILES 1000
#define FILENAMELENGTH 255
char tempfilename[FILENAMELENGTH], guidefilename[FILENAMELENGTH];
char headerfilename[FILENAMELENGTH], filepattern[FILENAMELENGTH];
char searchpath[FILENAMELENGTH], currentdir[FILENAMELENGTH];
char messagebuffer[FILENAMELENGTH], indexbuffer[99];
int indexentrylength=17, columns=4;
FILE *outfile, *infile, *guidefile, *headerfile;
struct FileInfoBlock *FileInfo;
struct DiskObject *DiskObj;
struct WBArg *WBArguments;
struct WBStartup *WBMessage;
struct Window *MyWindow;
struct Gadget *MyGadgets[16];
struct TextAttr MyFont = { "topaz.font", 8, 0, 0, };
struct Library *IconBase;
struct Library *IntuitionBase;
struct Library *GfxBase;
struct Library *GadToolsBase;
struct Library *AslBase;
short SortIndex=TRUE, SubIndex=FALSE, StrictAscii=TRUE;
struct NewMenu MyNewMenu[] = {
{ NM_TITLE, "Project", 0, 0, 0, 0, },
{ NM_ITEM, "Compile", "C", 0, 0, 0, },
{ NM_ITEM, "Quit", "Q", 0, 0, 0, },
{ NM_TITLE, "Help", 0, 0, 0, 0, },
{ NM_ITEM, "Help...", "H", 0, 0, 0, },
{ NM_ITEM, "About...", "A", 0, 0, 0, },
{ NM_END, NULL, 0, 0, 0, 0, },};
struct TagItem frtags[] =
{ ASL_Hail, (ULONG)"Makeguide v2.0 file request",
ASL_Height, 180,
ASL_Width, 300,
ASL_LeftEdge, 100,
ASL_TopEdge, 20,
ASL_OKText, (ULONG)"OK",
ASL_CancelText, (ULONG)"Cancel",
ASL_File, (ULONG)"",
ASL_Dir, (ULONG)"SYS:",
TAG_DONE };
struct EasyStruct MyEasyStruct =
{ sizeof(struct EasyStruct),
0,
"About MakeGuide v2.0",
"MakeGuide v2.0 (c)\nCompiles a list of ascii documents\ninto an AmigaGuide file.\nWritten by Jan Klok.",
"Okay!" };
struct EasyStruct HelpEasyStruct =
{ sizeof(struct EasyStruct),
0,
"MakeGuide v2.0 help",
"MakeGuide v2.0 (c)\nSorry, there is currently no online help available.\nRefer to the doc file for more information.",
"I'll do that!" };
void ShowMessage(STRPTR message)
{ GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
GTTX_Text, message, TAG_END);
}
void ShowError(STRPTR ErrorMessage)
{ GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
GTTX_Text, ErrorMessage, TAG_END);
if(infile) fclose(infile);
if(outfile) fclose(outfile);
if(guidefile) fclose(guidefile);
if(headerfile) fclose(headerfile);
if(outfile) remove(tempfilename);
if(FileInfo) free(FileInfo);
}
int ProcessFiles(void)
{ int error, i, j, k, s;
extern int errno;
unsigned char c='\0';
char *FileNames[MAXFILES];
short CheckAscii(char);
if(indexentrylength<=0)
{ ShowError("Indexentrylength must be greater than 0!");
return(5);
};
if(columns==0)
{ ShowError("Columns must be different from 0!");
return(5);
};
error = getcd(0,currentdir);
if(error!=NULL)
{ ShowError("Couldn't lock current directory!");
return(5);
};
if(strlen(searchpath)==0)
{ strcpy(currentdir,searchpath);
GT_SetGadgetAttrs(MyGadgets[MYGAD_SOURCE], MyWindow, NULL,
GTST_String, searchpath, TAG_END);
}
error = chdir(searchpath);
if(error!=NULL)
{ ShowError("Couldn't change to source directory!");
return(5);
};
if(strlen(tempfilename)==0)
{ strcpy(tempfilename,"ram:tmp");
GT_SetGadgetAttrs(MyGadgets[MYGAD_TEMP], MyWindow, NULL,
GTST_String, tempfilename, TAG_END);
}
outfile = fopen(tempfilename,"w");
if(outfile==NULL)
{ ShowError("Temporary file could not be opened for output!");
return(5);
};
if(strlen(guidefilename)==0)
{ strcpy(guidefilename,"ram:Guide.guide");
GT_SetGadgetAttrs(MyGadgets[MYGAD_DEST], MyWindow, NULL,
GTST_String, guidefilename, TAG_END);
}
guidefile = fopen(guidefilename,"w");
if(guidefile==NULL)
{ ShowError("Output file for guide could not be opened!");
return(5);
};
if(strlen(headerfilename)==0)
{ headerfile=NULL;
ShowMessage("Using default header...");
}
else
{ headerfile = fopen(headerfilename,"r");
if(headerfile==NULL)
{ ShowError("Headerfile for guide could not be opened!");
return(5);
};
};
FileInfo = malloc(sizeof(struct FileInfoBlock));
if(FileInfo==NULL)
{ ShowError("Allocation of fileinfoblock failed!");
return(5);
};
sprintf(messagebuffer,"Scanning directory %s...",searchpath);
ShowMessage(messagebuffer);
if(filepattern==NULL) strcpy("#?",filepattern);
error = dfind(FileInfo,filepattern,0);
if(error != NULL)
{ ShowError("No files found for this filefilter!");
return(5);
};
s=0;
while(error==0)
{ if(NULL != strcmp(headerfilename,FileInfo->fib_FileName))
{ FileNames[s] = malloc(strlen(FileInfo->fib_FileName)+1);
if(FileNames[s]==NULL)
{ ShowError("Memory allocation for filename failed!");
return(5);
};
strcpy(FileNames[s],FileInfo->fib_FileName);
s++;
if(s==MAXFILES)
{ ShowError("Sorry, MAXFILES inputfiles is the limit!");
return(5);
};
if(error==0)
{ fprintf(outfile,"@node \"%s\" \"%s\"\n",FileInfo->fib_FileName,FileInfo->fib_FileName);
sprintf(messagebuffer,"Processing file %d:'%s'",s,FileInfo->fib_FileName);
ShowMessage(messagebuffer);
infile = fopen(FileInfo->fib_FileName,"r");
if(infile == NULL)
{ ShowError("Input file could not be opened!");
return(5);
};
c = getc(infile);
while(CheckAscii(c) != NULL)
{ putc(c,outfile);
c = getc(infile);
}
if(c != EOF)
{ sprintf(messagebuffer,"'%s' contains binary!",FileInfo->fib_FileName);
ShowError(messagebuffer);
return(5);
}
fprintf(outfile,"\n@endnode\n\n");
fclose(infile);
}
}
error = dnext(FileInfo);
}
if(SortIndex)
{ ShowMessage("Sorting filenames...");
strsrt(FileNames,s);
}
ShowMessage("Writing main node...");
fprintf(guidefile,"@database %s\n\n",guidefilename);
fprintf(guidefile,"@node main \"%s\"\n",guidefilename);
ShowMessage("Writing header...");
if (headerfile)
{ c = getc(headerfile);
while(CheckAscii(c) != NULL)
{ putc(c,guidefile);
c = getc(headerfile);
}
fprintf(guidefile,"\n");
if(c != EOF)
{ ShowError("The header file contains binary!");
return(5);
}
}
else
{ fprintf(guidefile,"This guide was created using MakeGuide v2.0 by Jan Klok.\n");
fprintf(guidefile,"This guide contains %d docfiles\n",s);
}
k=columns;
for(i=0;i<s;i++)
{ strncpy(indexbuffer,FileNames[i],indexentrylength);
for(j=strlen(indexbuffer);j<indexentrylength;j++)
indexbuffer[j]=' ';
indexbuffer[j]='\0';
if(k==columns)
fprintf(guidefile,"\n ");
k--;
if(k==0)
k=columns;
fprintf(guidefile,"@{\"%s\" link \"%s\"}",indexbuffer,FileNames[i]);
free(FileNames[i]);
}
fprintf(guidefile,"\n@endnode\n\n");
fclose(outfile);
outfile = fopen(tempfilename,"r");
ShowMessage("Writing compiled nodes...");
c = getc(outfile);
while(CheckAscii(c) != NULL)
{ putc(c,guidefile);
c = getc(outfile);
}
DiskObj=GetDefDiskObject(WBPROJECT);
DiskObj->do_DefaultTool="AmigaGuide";
if(DiskObj!=NULL) PutDiskObject(guidefilename,DiskObj);
ShowError("Compilation successfully completed!");
return(0);
}
short CheckAscii(c)
char c;
{ short list[]={'\x95','\x97','\x98','\x9c','\x9d','\x9e','\x9f','\xa0',
'\xa1','\xa2','\xa3','\xa4','\xa5','\xa6','\xa9','\xaa',
'\xab','\xac','\xad','\xaf','\xb0','\xb2','\xb3','\xb4',
'\xb7','\xb9','\xba','\xbb','\xbf','\xc0','\xc1','\xc2',
'\xc3','\xc4','\xc5','\xca','\xcd','\xce','\xd0','\xd1',
'\xd7','\xd8','\xd9','\xda','\xdf','\xe5','\xea','\xee',
'\xf0','\xf7','\xf8','\xf9','\x00'};
short rc;
int i;
rc=isascii(c);
if(!StrictAscii)
{ if(rc==0)
{ for(i=0;list[i]!='\x00';i++)
if(list[i]==c)
{ rc=c;
break;
}
}
}
return(rc);
}
void GetWindowContents(void)
{ GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
GTTX_Text, "Processing files...", TAG_END);
strcpy(filepattern,((struct StringInfo *)MyGadgets[MYGAD_PAT]->SpecialInfo)->Buffer);
strcpy(searchpath,((struct StringInfo *)MyGadgets[MYGAD_SOURCE]->SpecialInfo)->Buffer);
strcpy(guidefilename,((struct StringInfo *)MyGadgets[MYGAD_DEST]->SpecialInfo)->Buffer);
strcpy(tempfilename,((struct StringInfo *)MyGadgets[MYGAD_TEMP]->SpecialInfo)->Buffer);
strcpy(headerfilename,((struct StringInfo *)MyGadgets[MYGAD_HEAD]->SpecialInfo)->Buffer);
indexentrylength=((struct StringInfo *)MyGadgets[MYGAD_LEN]->SpecialInfo)->LongInt;
columns=((struct StringInfo *)MyGadgets[MYGAD_COLS]->SpecialInfo)->LongInt;
SortIndex=(MyGadgets[MYGAD_SORT]->Flags & GFLG_SELECTED);
SubIndex=(MyGadgets[MYGAD_SUBIDX]->Flags & GFLG_SELECTED);
StrictAscii=(MyGadgets[MYGAD_ASCCHECK]->Flags & GFLG_SELECTED);
}
void HandleGadgetEvent(struct Gadget *gad, UWORD code)
{ struct FileRequester *fr;
switch(gad->GadgetID)
{ case MYGAD_SOURCEBUT:
if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
{ if(AslRequest(fr,NULL))
GT_SetGadgetAttrs(MyGadgets[MYGAD_SOURCE], MyWindow, NULL,
GTST_String, fr->rf_Dir, TAG_END);
FreeAslRequest(fr);
}
break;
case MYGAD_DESTBUT:
if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
{ if(AslRequest(fr,NULL))
{ strcpy(guidefilename,fr->rf_Dir);
AddPart(guidefilename,fr->rf_File,FILENAMELENGTH);
GT_SetGadgetAttrs(MyGadgets[MYGAD_DEST], MyWindow, NULL,
GTST_String, guidefilename, TAG_END);
}
FreeAslRequest(fr);
}
break;
case MYGAD_TEMPBUT:
if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
{ if(AslRequest(fr,NULL))
{ strcpy(tempfilename,fr->rf_Dir);
AddPart(tempfilename,fr->rf_File,FILENAMELENGTH);
GT_SetGadgetAttrs(MyGadgets[MYGAD_TEMP], MyWindow, NULL,
GTST_String, tempfilename, TAG_END);
}
FreeAslRequest(fr);
}
break;
case MYGAD_HEADBUT:
if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
{ if(AslRequest(fr,NULL))
{ strcpy(headerfilename,fr->rf_Dir);
AddPart(headerfilename,fr->rf_File,FILENAMELENGTH);
GT_SetGadgetAttrs(MyGadgets[MYGAD_HEAD], MyWindow, NULL,
GTST_String, headerfilename, TAG_END);
}
FreeAslRequest(fr);
}
break;
case MYGAD_GOBUT:
GetWindowContents();
ProcessFiles();
break;
}
}
void HandleVanillaKey(UWORD code)
{ code=toupper(code);
switch(code)
{ case 'P':
ActivateGadget(MyGadgets[MYGAD_PAT], MyWindow, NULL);
break;
case 'S':
ActivateGadget(MyGadgets[MYGAD_SOURCE], MyWindow, NULL);
break;
case 'D':
ActivateGadget(MyGadgets[MYGAD_DEST], MyWindow, NULL);
break;
case 'T':
ActivateGadget(MyGadgets[MYGAD_TEMP], MyWindow, NULL);
break;
case 'H':
ActivateGadget(MyGadgets[MYGAD_HEAD], MyWindow, NULL);
break;
case 'C':
GetWindowContents();
ProcessFiles();
break;
case 'I':
if(MyGadgets[MYGAD_SORT]->Flags & GFLG_SELECTED)
GT_SetGadgetAttrs(MyGadgets[MYGAD_SORT], MyWindow, NULL,
GTCB_Checked, FALSE, TAG_END);
else
GT_SetGadgetAttrs(MyGadgets[MYGAD_SORT], MyWindow, NULL,
GTCB_Checked, TRUE, TAG_END);
break;
case 'B':
if(MyGadgets[MYGAD_SUBIDX]->Flags & GFLG_SELECTED)
GT_SetGadgetAttrs(MyGadgets[MYGAD_SUBIDX], MyWindow, NULL,
GTCB_Checked, FALSE, TAG_END);
else
GT_SetGadgetAttrs(MyGadgets[MYGAD_SUBIDX], MyWindow, NULL,
GTCB_Checked, TRUE, TAG_END);
break;
case 'A':
if(MyGadgets[MYGAD_ASCCHECK]->Flags & GFLG_SELECTED)
GT_SetGadgetAttrs(MyGadgets[MYGAD_ASCCHECK], MyWindow, NULL,
GTCB_Checked, FALSE, TAG_END);
else
GT_SetGadgetAttrs(MyGadgets[MYGAD_ASCCHECK], MyWindow, NULL,
GTCB_Checked, TRUE, TAG_END);
break;
}
}
struct Gadget *CreateAllGadgets(struct Gadget **glistptr, void *VisualInfo)
{ struct NewGadget ng;
struct Gadget *gad;
gad = CreateContext(glistptr);
ng.ng_TopEdge = 25;
ng.ng_LeftEdge = 160;
ng.ng_Width = 200;
ng.ng_Height = 12;
ng.ng_GadgetText = "_Pattern";
ng.ng_TextAttr = &MyFont;
ng.ng_VisualInfo = VisualInfo;
ng.ng_GadgetID = MYGAD_PAT;
ng.ng_Flags = NG_HIGHLABEL;
MyGadgets[MYGAD_PAT] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, filepattern,
GTST_MaxChars, 50,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_GadgetText = "_Source directory";
ng.ng_GadgetID = MYGAD_SOURCE;
MyGadgets[MYGAD_SOURCE] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, searchpath,
GTST_MaxChars, FILENAMELENGTH - 50,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_Width = 40;
ng.ng_GadgetText = ">>";
ng.ng_GadgetID = MYGAD_SOURCEBUT;
MyGadgets[MYGAD_SOURCEBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 200;
ng.ng_GadgetText = "_Destination";
ng.ng_GadgetID = MYGAD_DEST;
MyGadgets[MYGAD_DEST] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, guidefilename,
GTST_MaxChars, FILENAMELENGTH,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_Width = 40;
ng.ng_GadgetText = ">>";
ng.ng_GadgetID = MYGAD_DESTBUT;
MyGadgets[MYGAD_DESTBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 200;
ng.ng_GadgetText = "_Temporary file";
ng.ng_GadgetID = MYGAD_TEMP;
MyGadgets[MYGAD_TEMP] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, tempfilename,
GTST_MaxChars, FILENAMELENGTH,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_Width = 40;
ng.ng_GadgetText = ">>";
ng.ng_GadgetID = MYGAD_TEMPBUT;
MyGadgets[MYGAD_TEMPBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 200;
ng.ng_GadgetText = "_Header file";
ng.ng_GadgetID = MYGAD_HEAD;
MyGadgets[MYGAD_HEAD] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, headerfilename,
GTST_MaxChars, FILENAMELENGTH,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_Width = 40;
ng.ng_GadgetText = ">>";
ng.ng_GadgetID = MYGAD_HEADBUT;
MyGadgets[MYGAD_HEADBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 40;
ng.ng_GadgetText = "Index entry _length";
ng.ng_GadgetID = MYGAD_LEN;
MyGadgets[MYGAD_LEN] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
GTIN_Number, indexentrylength,
GTIN_MaxChars, 2,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_GadgetText = "Index entry _columns";
ng.ng_GadgetID = MYGAD_COLS;
MyGadgets[MYGAD_COLS] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
GTIN_Number, columns,
GTIN_MaxChars, 1,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 200;
ng.ng_Height = 20;
ng.ng_GadgetText = "Sort _index";
ng.ng_GadgetID = MYGAD_SORT;
MyGadgets[MYGAD_SORT] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
GTCB_Checked, SortIndex,
GT_Underscore, '_',
TAG_END);
ng.ng_LeftEdge += 220;
ng.ng_Width = 200;
ng.ng_Height = 20;
ng.ng_GadgetText = "Create su_bindex";
ng.ng_GadgetID = MYGAD_SUBIDX;
MyGadgets[MYGAD_SUBIDX] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
GTCB_Checked, SubIndex,
GT_Underscore, '_',
GA_Disabled, TRUE,
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_LeftEdge -= 220;
ng.ng_Width = 200;
ng.ng_Height = 20;
ng.ng_GadgetText = "Strict _ascii check";
ng.ng_GadgetID = MYGAD_ASCCHECK;
MyGadgets[MYGAD_ASCCHECK] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
GTCB_Checked, StrictAscii,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 15;
ng.ng_GadgetText = "_Compile";
ng.ng_GadgetID = MYGAD_GOBUT;
MyGadgets[MYGAD_GOBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 33;
ng.ng_LeftEdge = 5;
ng.ng_Width = 455;
ng.ng_Height = 12;
ng.ng_GadgetText = "";
ng.ng_GadgetID = MYGAD_MSG;
MyGadgets[MYGAD_MSG] = gad = CreateGadget(TEXT_KIND, gad, &ng,
GTTX_Text, "Ready when you are!",
GTTX_Border, TRUE,
TAG_END);
return(gad);
}
void ProcessWindowEvents(struct Menu *MenuStrip)
{ struct IntuiMessage *imsg;
ULONG imsgClass;
UWORD imsgCode;
UWORD menuNumber;
UWORD menuNum;
UWORD itemNum;
UWORD subNum;
struct MenuItem *item;
struct Gadget *gad;
BOOL terminated = FALSE;
while(!terminated)
{ Wait(1 << MyWindow->UserPort->mp_SigBit);
while((!terminated) && (imsg=GT_GetIMsg(MyWindow->UserPort)))
{ gad = (struct Gadget *)imsg->IAddress;
imsgClass = imsg->Class;
imsgCode = imsg->Code;
GT_ReplyIMsg(imsg);
switch(imsgClass)
{ case IDCMP_GADGETDOWN:
case IDCMP_MOUSEMOVE:
case IDCMP_GADGETUP:
HandleGadgetEvent(gad, imsgCode);
break;
case IDCMP_VANILLAKEY:
HandleVanillaKey(imsgCode);
break;
case IDCMP_CLOSEWINDOW:
terminated=TRUE;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(MyWindow);
GT_EndRefresh(MyWindow,TRUE);
break;
case IDCMP_MENUPICK:
menuNumber = imsg->Code;
while((menuNumber != MENUNULL) && (!terminated))
{ item = ItemAddress(MenuStrip, menuNumber);
menuNum = MENUNUM(menuNumber);
itemNum = ITEMNUM(menuNumber);
subNum = SUBNUM(menuNumber);
if((menuNum == 0) && (itemNum == 0))
ProcessFiles();
if((menuNum == 0) && (itemNum == 1))
terminated=TRUE;
if((menuNum == 1) && (itemNum == 0))
EasyRequest(NULL,&HelpEasyStruct,NULL);
if((menuNum == 1) && (itemNum == 1))
EasyRequest(NULL,&MyEasyStruct,NULL);
menuNumber=item->NextSelect;
}
break;
}
}
}
}
void OpenGadToolsWindow(void)
{ struct TextFont *Font;
struct Screen *MyScreen;
struct Gadget *GadgetList;
void *VisualInfo;
struct Menu *MenuStrip;
if(NULL==(Font=OpenFont(&MyFont)))
ShowError("Failed to open topaz 80");
else
{ if(NULL==(MyScreen = LockPubScreen(NULL)))
ShowError("Couldn't lock default public screen");
else
{ if(NULL==(VisualInfo = GetVisualInfo(MyScreen, TAG_END)))
ShowError("GetVisualInfo() failed");
else
{ if(NULL==CreateAllGadgets(&GadgetList, VisualInfo))
ShowError("CreateAllGadgets() failed");
else
{ if(NULL==(MyWindow=OpenWindowTags(NULL,
WA_Title, "MakeGuide v2.0",
WA_Gadgets, GadgetList,
WA_AutoAdjust, TRUE,
WA_Width, 465,
WA_InnerHeight, 180,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_Activate, TRUE,
WA_CloseGadget, TRUE,
WA_SimpleRefresh, TRUE,
WA_IDCMP, IDCMP_CLOSEWINDOW |
IDCMP_REFRESHWINDOW |
IDCMP_VANILLAKEY |
SLIDERIDCMP |
STRINGIDCMP |
BUTTONIDCMP |
IDCMP_MENUPICK,
WA_PubScreen, MyScreen,
TAG_END)))
ShowError("OpenWindow() failed");
else
{ /* Now we can attach the menustrip */
if(NULL==(MenuStrip=CreateMenus(MyNewMenu, TAG_END)))
ShowError("Couldn't create menu");
else
{ if(NULL==(LayoutMenus(MenuStrip,VisualInfo,TAG_END)))
ShowError("Couldn't layout menus");
else
{ if(NULL==(SetMenuStrip(MyWindow, MenuStrip)))
ShowError("Couldn't set menustrip");
else
{ GT_RefreshWindow(MyWindow, NULL);
ProcessWindowEvents(MenuStrip);
CloseWindow(MyWindow);
}
}
FreeGadgets(GadgetList);
FreeVisualInfo(VisualInfo);
}
UnlockPubScreen(NULL, MyScreen);
}
CloseFont(Font);
}
}
}
}
}
main(int argc, char **argv)
{ char *toolvalue=NULL;
if(argc != 0)
{ printf("\nMakeGuide v2.0 - by Jan Klok\n");
printf("Run me from Workbench\n\nValid tooltypes are:\n");
printf("FILEFILTER=<wildcard>\n");
printf("SOURCEDIR=<directory>\n");
printf("DESTINATION=<filename>\n");
printf("TEMPFILE=<filename>\n");
printf("HEADERFILE=<filename>\n");
printf("Refer to the doc file for more information.\n");
}
else
{ if(NULL==(IconBase=OpenLibrary("icon.library", 37)))
ShowError("Requires v37 icon.library");
else
{ if(NULL==(IntuitionBase=OpenLibrary("intuition.library", 37)))
ShowError("Requires v37 intuition.library");
else
{ if(NULL==(GfxBase=OpenLibrary("graphics.library",37)))
ShowError("Requires v37 graphics.library");
else
{ if(NULL==(GadToolsBase=OpenLibrary("gadtools.library", 37)))
ShowError("Requires v37 intuition.library");
else
{ if(NULL==(AslBase=OpenLibrary("asl.library", 37)))
ShowError("Requires v37 asl.library");
else
{ WBMessage=(struct WBStartup *)argv;
WBArguments=WBMessage->sm_ArgList;
DiskObj = GetDiskObject(WBArguments->wa_Name);
strcpy(filepattern,FindToolType(DiskObj->do_ToolTypes,"FILEFILTER"));
strcpy(searchpath,FindToolType(DiskObj->do_ToolTypes,"SOURCEDIR"));
strcpy(guidefilename,FindToolType(DiskObj->do_ToolTypes,"DESTINATION"));
strcpy(tempfilename,FindToolType(DiskObj->do_ToolTypes,"TEMPFILE"));
strcpy(headerfilename,FindToolType(DiskObj->do_ToolTypes,"HEADERFILE"));
toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"STRICTASCII");
if(MatchToolValue(toolvalue,"YES")) StrictAscii=TRUE;
if(MatchToolValue(toolvalue,"NO")) StrictAscii=FALSE;
toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"SORTINDEX");
if(MatchToolValue(toolvalue,"YES")) SortIndex=TRUE;
if(MatchToolValue(toolvalue,"NO")) SortIndex=FALSE;
toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"SUBINDEX");
if(MatchToolValue(toolvalue,"YES")) SubIndex=TRUE;
if(MatchToolValue(toolvalue,"NO")) SubIndex=FALSE;
OpenGadToolsWindow();
FreeDiskObject(DiskObj);
CloseLibrary(AslBase);
}
}
CloseLibrary(GadToolsBase);
}
CloseLibrary(GfxBase);
}
CloseLibrary(IntuitionBase);
}
CloseLibrary(IconBase);
}
}